import React from 'react';
import { Switch, Route, Redirect } from "react-router-dom"
import { MyRouter } from "../utils/interface"
interface IProps {
    routes: MyRouter[]
}
const RouterView: React.FC<IProps> = (props) => {
    return <Switch>
        {
            props.routes.map((item, index) => {
                if (item.redirect) {
                    return <Redirect key={index} from={item.path} to={item.redirect}></Redirect>
                }
                return <Route path={item.path} key={index} render={(api) => {
                    if (item.children) {
                        return <item.component {...api} routes={item.children}></item.component>
                    }
                    return <item.component {...api} />
                }}></Route>
            })
        }
    </Switch>
}
export default RouterView